// packageE/membertop/membertop.js
const app = getApp();
const skinBehavior = require('../../../utils/themeSkin/skinBehavior');

Component({
  behaviors: [skinBehavior],
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    },
    is_login: {
      type: Number
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage:  `${app.globalData.imgPath}image.png`,
    nickname: "昵称",
    uid: "--",
    level_name: "普通会员",
    imgPath: app.globalData.imgPath,
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    toEditAvatar(){
      wx.navigateTo({
        url: '/packageA/member/new_userinfo/new_userinfo',
      })
    },
    TapEdit(){
      this.triggerEvent('TapEditChild')
    },
    copybtn(e) {
      let inviteCode = e.target.dataset.num;
      wx.setClipboardData({
        data: inviteCode ? inviteCode : "",
        success(res) {
          wx.showToast({
            icon: "none",
            title: "复制成功",
            duration: 1000,
          });
        },
      });
    },
    //跳转至会员权益
    gotoMemberGrade() {
      const { grade_type, data } = this.data.datas;// grade_type：会员等级类型
      let pageUrl;
      switch (grade_type) {
      case '1':
        if(data.jump_level_page == 1) pageUrl = '/packageB/member/MemberGradeList/MemberGradeList';
        break;
      case '2':
        // 经销商等级
        if (!data.level_name && !data.is_agent) {
          pageUrl = '/packageA/member/extension/ExtensionApply/ExtensionApply';
        } else {
          pageUrl = '/packageB/member/income/teamAgentCenter/teamAgentCenter';
        }
        break;
      case '3':
        // 分销商等级
        if (!data.level_name && !data.is_agent) {
          pageUrl = '/packageA/member/extension/ExtensionApply/ExtensionApply';
        } else {
          pageUrl = '/mircoApp/commission/distribution/index';
        }
        break;
      default:
        break;
      }

      if(pageUrl) {
        wx.navigateTo({
          url: pageUrl,
        });
      }
    },

    toLogin(){
      this.triggerEvent("toLogin");
    }
  },
});
